package com.study.reactor.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.study.reactor.vo.FaceBookVO;
import com.study.reactor.vo.ItemVO;

import java.util.List;

/**
 * @author yuantongqin
 * desc:
 * 2020-11-16
 */
public class FastjsonTest {

    public static  <T> List<T> getA(Class<T> tClass,String content){
        FaceBookVO<T> listFaceBookVO = JSON.parseObject(content, new TypeReference<FaceBookVO<T>>(tClass) {
        }.getType());
//        return JSON.parseObject(content).getJSONArray("data").toJavaList(tClass);
        return listFaceBookVO.getData();
    }

    public static void main(String[] args) {
        String content = "{\n" +
                "    \"data\": [\n" +
                "        {\n" +
                "            \"account_id\": \"355889052493286\",\n" +
                "            \"id\": \"act_355889052493286\"\n" +
                "        }]}";
        List<ItemVO> a = getA(ItemVO.class, content);
        int b = 10;
        System.out.println(a.toString());
    }

    public <T> List<T> test(Class<T> a,String content){
        List<T> facebookResult = JSON.parseObject(content, new TypeReference<List<T>>(a) {
        });
        return facebookResult;
    }
}
